package com.zxb.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zxb.common.annotation.Log;
import com.zxb.common.core.controller.BaseController;
import com.zxb.common.core.domain.AjaxResult;
import com.zxb.common.enums.BusinessType;
import com.zxb.system.domain.Beehives;
import com.zxb.system.service.IBeehivesService;
import com.zxb.common.utils.poi.ExcelUtil;
import com.zxb.common.core.page.TableDataInfo;

/**
 * 蜂箱Controller
 * 
 * @author YY
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/system/beehives")
public class BeehivesController extends BaseController
{
    @Autowired
    private IBeehivesService beehivesService;

    /**
     * 查询蜂箱列表
     */
    @PreAuthorize("@ss.hasPermi('system:beehives:list')")
    @GetMapping("/list")
    public TableDataInfo list(Beehives beehives)
    {
        startPage();
        List<Beehives> list = beehivesService.selectBeehivesList(beehives);
        return getDataTable(list);
    }

    /**
     * 导出蜂箱列表
     */
    @PreAuthorize("@ss.hasPermi('system:beehives:export')")
    @Log(title = "蜂箱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Beehives beehives)
    {
        List<Beehives> list = beehivesService.selectBeehivesList(beehives);
        ExcelUtil<Beehives> util = new ExcelUtil<Beehives>(Beehives.class);
        util.exportExcel(response, list, "蜂箱数据");
    }

    /**
     * 获取蜂箱详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:beehives:query')")
    @GetMapping(value = "/{beehiveId}")
    public AjaxResult getInfo(@PathVariable("beehiveId") Long beehiveId)
    {
        return success(beehivesService.selectBeehivesByBeehiveId(beehiveId));
    }

    /**
     * 新增蜂箱
     */
    @PreAuthorize("@ss.hasPermi('system:beehives:add')")
    @Log(title = "蜂箱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Beehives beehives)
    {
        return toAjax(beehivesService.insertBeehives(beehives));
    }

    /**
     * 修改蜂箱
     */
    @PreAuthorize("@ss.hasPermi('system:beehives:edit')")
    @Log(title = "蜂箱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Beehives beehives)
    {
        return toAjax(beehivesService.updateBeehives(beehives));
    }

    /**
     * 删除蜂箱
     */
    @PreAuthorize("@ss.hasPermi('system:beehives:remove')")
    @Log(title = "蜂箱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{beehiveIds}")
    public AjaxResult remove(@PathVariable Long[] beehiveIds)
    {
        return toAjax(beehivesService.deleteBeehivesByBeehiveIds(beehiveIds));
    }
}
